package com.xxxx.api.utils;

import com.alibaba.fastjson.JSON;
import com.xxxx.api.pojo.Admin;

import java.security.MessageDigest;
import java.util.Base64;


public class Md5Util {

    public static String encode(String msg) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("md5");
            return Base64.getEncoder().encodeToString(messageDigest.digest(msg.getBytes()));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    public static void main(String[] args) {
        System.out.println(encode("123"));
        Admin admin=new Admin();
        admin.setUserName("sad");
        admin.setPassword("123");
        String s = JSON.toJSONString(admin);
        System.out.println(s);
        System.out.println("======");
        Admin admin1 = JSON.parseObject(s, Admin.class);
        System.out.println(admin1.toString());

    }

}
